package leetcode.median;

public class $58_LengthOfLastWord {
    public int lengthOfLastWord(String s) {
        int i = s.length() - 1;
        int maxLen = 0;
        while (i >= 0 && s.charAt(i) == ' ') {
            i--;
        }
        while (i >= 0) {
            if (s.charAt(i) != ' ') {
                maxLen++;
            } else {
                break;
            }
        }
        return maxLen;
    }
}
